package org.vt.scheduleapp;

import java.io.FileNotFoundException;
import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class NotesWriter extends Activity {
	private NotesReader reader;

	private Notes note;
	private String data;

	private EditText mBodyText;
	private EditText mTitleText;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.note_edit);
		setTitle(R.string.edit_note);

		Button confirmButton = (Button) findViewById(R.id.confirm);
		reader = new NotesReader(this);

		try {
			data = reader.readFile();
			mBodyText.setText(data);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		confirmButton.setOnClickListener(new View.OnClickListener() {

			public void onClick(View view) {
				setResult(RESULT_OK);
				finish();
			}
		});
	}


	protected void onSaveInstanceState(Bundle outState)
	{
		super.onSaveInstanceState(outState);
		saveState();
	}

	private void saveState()
	{			
		String title = mTitleText.getText().toString();
		String body = mBodyText.getText().toString();
		note.createNote(title, body);
	}
}
